package com.me.crgame.escenas.mapaventura;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.me.crgame.core.ActorTouchListener;
import com.me.crgame.core.EnumEscena;
import com.me.crgame.core.EnumTransicion;
import com.me.crgame.core.Escena;
import com.me.crgame.core.actores.ActorButton;


public class EscenaAventura extends Escena implements ActorTouchListener {//implements ApplicationListener {//implements ActorTouchListener {
	Image texture;
	ActorButton opcionAtras;
	
	boolean f;
	ActorButton planetas;
	
	float x,y;
	
	//private Stage stage;
	private Table container;
	private Sprite di;
		
	public EscenaAventura() {
		super();
		x=0;
		y=0;
		f=false;	
		Skin skin = new Skin(Gdx.files.internal("data/juego/uiskin.json"));
	
		container = new Table();
		container.setFillParent(true);
		di= new Sprite((new Texture(Gdx.files.internal("data/sistema_menus/mapa_aventura/aventura2.png"))));
		//container.setBackground(new SpriteDrawable(di));
		Table table = new Table();
		table.setBackground(new SpriteDrawable(di));
		//container.setBackground(new SpriteDrawable(di));
		// table.debug();

		//final ScrollPane scroll = new ScrollPane(container, skin);
		
		final ScrollPane scroll = new ScrollPane(table, skin);

		table.pad(10).defaults().expandX().space(8);
		for (int i = 0; i < 10; i++) {
			table.columnDefaults(i);
			 ActorButton bot = new ActorButton("data/sistema_menus/menu_principal/planeta.png", this);
			table.addActor(bot);
			if(f)
			bot.setPosition(100+x,400);
			else 
				bot.setPosition(100+x,120);
			bot.setScale(0.3f);
			x=x+150;
			f= !f;
		}
		
		
	
		scroll.setFlingTime(2f);
		scroll.setOverscroll(false, false);
		scroll.setScrollingDisabled(false,true);
		scroll.setScrollX(100);
		scroll.setScrollPercentX(100);
		scroll.setSmoothScrolling(false);
		scroll.setupFadeScrollBars(0f, 0f);
		
		
		
		
		container.add(scroll);
	
		
		
	//	container.columnDefaults(2);
	//	scroll.setFillParent(true);
	//	scroll.setHeight(this.getHeight());
	//	scroll.setWidth(this.getWidth());
	
		
	//	container.add(scroll).expand().fill().colspan(2);
	//	container.columnDefaults(2).space(10).padBottom(10);
		
		
		di= new Sprite((new Texture(Gdx.files.internal("data/sistema_menus/mapa_aventura/aventura.png"))));
	
		Table table1 = new Table();
		table1.setBackground(new SpriteDrawable(di));
		//container.setBackground(new SpriteDrawable(di));
		// table.debug();

		//final ScrollPane scroll = new ScrollPane(container, skin);
		
		final ScrollPane scroll1 = new ScrollPane(table1, skin);
		//	table.setRotation(90);
	/*	InputListener stopTouchDown = new InputListener() {
			public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
				event.stop();
				return false;
			}
		};
*/		x=0;
		
		table1.pad(10).defaults().expandX().space(8);
		for (int i = 0; i < 10; i++) {
			table1.columnDefaults(i);
			 ActorButton bot = new ActorButton("data/sistema_menus/menu_principal/planeta.png", this);
			table1.addActor(bot);
			if(f)
			bot.setPosition(100+x,400);
			else 
				bot.setPosition(100+x,120);
			bot.setScale(0.3f);
			x=x+150;
			f= !f;
		}
		/*container.pad(10).defaults().expandY().space(4);
		for (int i = 0; i < 10; i++) {
			container.columnDefaults(i);
			 ActorButton bot = new ActorButton("data/sistema_menus/menu_principal/planeta.png", this);
			 container.addActor(bot);
			if(f)
			bot.setPosition(100+x,400);
			else 
				bot.setPosition(100+x,120);
			bot.setScale(0.3f);
			x=x+150;
			f= !f;
		}
		*/
	
	//	container.add(table1);
	//	container.debug();
	//	scroll.setWidth(Gdx.graphics.getWidth()*2);
	//	scroll.setHeight(Gdx.graphics.getHeight()*2);
		
	//	scroll1.setWidth(Gdx.graphics.getWidth()*2);
	//	scroll1.setHeight(Gdx.graphics.getHeight()*2);
		scroll1.pack();
		scroll1.setFlingTime(2f);
		scroll1.setOverscroll(false, false);
		scroll1.setScrollingDisabled(false,true);
		scroll1.setScrollX(100);
		scroll1.setScrollPercentX(100);
		scroll1.setSmoothScrolling(false);
		scroll1.setupFadeScrollBars(0f, 0f);
		container.add(scroll1).expand().fill();
		
	
		//scroll1.setX(scroll.getWidth());
		//scroll1.setY(scroll1.getHeight());
		//	container.padBottom(0);
		
		
		
	//	ScrollPane pane = new ScrollPane(container, skin);
		
		
		//	pane.setHeight(Gdx.graphics.getHeight()+200);
		//	pane.setWidth(Gdx.graphics.getWidth()+200);
		
	//	scroll1.setFillParent(true);
	//	scroll1.setHeight(this.getHeight());
	//	scroll1.setWidth(this.getWidth());
		//super.addActor(container);
	//	super.addActor(table);
		super.addActor(container);
		//pane.scale(3);
		
		//pane.setFillParent(true);
	//	pane.rotate(10);
		//super.addActor(container);
	//	Table table2 = new Table();
	//	table2.add(pane).expand().fill();
		
		
	//	super.addActor(table2);
		
		
	//	pane.setFillParent(true);
		container.setFillParent(true);
	//	table2.setFillParent(true);
	//	scroll1.setFillParent(true);
		
		
		//super.addActor(scroll);
	//	super.addActor(scroll1);
		
		
		
		
		
		
		
		
		
	

		opcionAtras = new ActorButton("data/sistema_menus/mapa_aventura/cohete_salir.png", this);
		super.addActor(opcionAtras);
		
	}

	
	public void render (float deltaTime) {
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		super.getSpriteBatch().begin();
	//	texture.draw(getSpriteBatch(), deltaTime);
		super.getSpriteBatch().end();
	
		super.render(deltaTime);
	}

	public void dispose () {
		//texture.dispose();
		this.getSpriteBatch().dispose();
	}

	public boolean needsGL20 () {
		return true;
	}
	
	protected void empiezaLaEscena() {
		//Aqui van las actions
	}

	protected void empiezaLaEscena(int transitionMode) {
	}

	protected void terminaLaEscena() {
		// TODO Auto-generated method stub

	}

	protected void pause(boolean gamePaused) {
		// TODO Auto-generated method stub

	}

	protected void update(float deltaTime) {
		// TODO Auto-generated method stub

	}


	@Override
	public boolean touchDown(ActorButton actor, float x, float y, int pointer) {
		
	//	if(actor == opcionAtras){
			
			activarVibracion(VIBRACIOM_CORTA);
			cambiarEscena(EnumEscena.MENU_PRINCIPAL, EnumTransicion.COMPUERTAS);
	//	}
		
		return false;
	}


	@Override
	public void touchDragged(ActorButton actor, float x, float y, int pointer) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void touchUp(ActorButton actor, float x, float y, int pointer) {
		// TODO Auto-generated method stub
		
	}	
}
